﻿namespace Borg.AttributeAnalyze.Result
{
    public class DuplicatedParameterDefinition : ResultBase
    {
        private readonly ParamDefinition _parameterDefinition;
        private readonly SlotDefinition _slotDefinition;

        public DuplicatedParameterDefinition(SlotDefinition slotDefinition, ParamDefinition parameterDefinition)
            : base(slotDefinition.Assembly, Component.SlotDefinition, ResultType.DuplicatedParameterDefinition, slotDefinition, null)
        {
            _slotDefinition = slotDefinition;
            _parameterDefinition = parameterDefinition;
        }

        public override string ToMsBuildMessageString()
        {
            var str = _parameterDefinition.HasDefaultValue
                ? string.Format("parameter defaultvalue: {0}", _parameterDefinition.DefaultValue)
                : string.Format("no parameter defaultvalue", new object[0]);

            return string.Format(
                "multiple parameter definition\n{0}slot name: {1}\n{0}interface:" +
                " {2}\n{0}parameter name: {3}\n{0}parameter type: {4}\n{0}{5}",
                new object[] { GetWhiteSpace(2), Name, _slotDefinition.TypeName,
                    _parameterDefinition.Name, _parameterDefinition.Type.Name, str });
        }

        public override MessageType MessageType
        {
            get { return MessageType.Error; }
        }
    }
}

